package com.cloudwise.gproject.service.impl;

import com.cloudwise.gproject.service.CommonFileService;
import com.cloudwise.gproject.util.OssProperty;
import com.cloudwise.gproject.util.OssUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @ fileName:CommonFileServiceImpl
 * @ description:
 * @ author:zhz
 * @ createTime:2021/3/23 15:41
 */
@Service
public class CommonFileServiceImpl implements CommonFileService {

    @Resource
    private OssProperty ossProperty;


    @Override
    public Map uploadFile(MultipartFile file, String savePath) {
        //文件上传  path = a/b/c/fdsfdsafasdfadsfawr.png
        String path = OssUtil.uploadFile(file, savePath, ossProperty);
        Map returnMap = new HashMap();
        returnMap.put("fileName",file.getOriginalFilename());
        // 访问路径：https://aiops02bucket.oss-cn-beijing.aliyuncs.com/a/b/c/fdsfdsafasdfadsfawr.png
        returnMap.put("filePath",ossProperty.getUrl()+path);
        return returnMap;
    }
}
